<!doctype html>
<html lang="en-us">
  <head>
    <meta charset="utf-16">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Test Model Description Language (Model Description Document) Javascript</title>
  </head>
  <body>
    <textarea id="output" rows="8"></textarea>
	
	<input type="text" value="" />
	<input type="button" value="test function" style="width:128px; height:24px" onclick="sasa()" />

	<!-- <script type="text/javascript" src="nxdat.js"></script> -->
	<script type="text/javascript" src="nxmodel.js"></script>
	
	<script type="text/javascript">
		var ESchemaNodeType = {
			EDTKT_INT: Module.SchemaNodeType.EDTKT_INT,
			EDTKT_REAL: Module.SchemaNodeType.EDTKT_REAL,
			EDTKT_VECTOR2: Module.SchemaNodeType.EDTKT_VECTOR2,
			EDTKT_VECTOR3: Module.SchemaNodeType.EDTKT_VECTOR3,
			EDTKT_VECTOR4: Module.SchemaNodeType.EDTKT_VECTOR4,
			EDTKT_STRING: Module.SchemaNodeType.EDTKT_STRING,
			EDTKT_INT_LIST: Module.SchemaNodeType.EDTKT_INT_LIST,
			EDTKT_REAL_LIST: Module.SchemaNodeType.EDTKT_REAL_LIST,
			EDTKT_VECTOR2_LIST: Module.SchemaNodeType.EDTKT_VECTOR2_LIST,
			EDTKT_VECTOR3_LIST: Module.SchemaNodeType.EDTKT_VECTOR3_LIST,
			EDTKT_VECTOR4_LIST: Module.SchemaNodeType.EDTKT_VECTOR4_LIST,
			EDTKT_STRING_LIST: Module.SchemaNodeType.EDTKT_STRING_LIST,
			EDTKT_NODE: Module.SchemaNodeType.EDTKT_NODE,
			EDTKT_LIST: Module.SchemaNodeType.EDTKT_LIST,
			EDTKT_MAP: Module.SchemaNodeType.EDTKT_MAP,
			EDTKT_TABLE: Module.SchemaNodeType.EDTKT_TABLE
		};
		
		function UdxNodeDescription(pNode){
			this.ownNode = pNode;
			
			this.getNodeDescription=function(){	
				var description = Module.getNodeDescription(this.ownNode.getNativeObj()); //节点描述信息
				return description;
			};
			
			this.getNodeConceptInfo=function(){
				var conceptTag = Module.getNodeConceptInfo(this.ownNode.getNativeObj());
				return conceptTag;
			};
			
			this.getNodeSpatialRefInfo=function(){
				var spatialTag = Module.getNodeSpatialRefInfo(this.ownNode.getNativeObj());
				return spatialTag;
			};
			
			this.getNodeUnitInfo=function(){
				var unitTag = Module.getNodeUnitInfo(this.ownNode.getNativeObj());
				return unitTag;
			};
			
			this.getNodeDataTemplateInfo=function(){
				var dataTemplateTag = Module.getNodeDataTemplateInfo(this.ownNode.getNativeObj());
				return dataTemplateTag;
			};
			
			this.modifyNodeDescription=function(descriptionInfo){
				Module.modifyNodeDescription(this.ownNode.getNativeObj(), descriptionInfo); //修改节点描述信息
			};
			
			this.modifyNodeConceptInfo=function(conceptTag){
				Module.modifyNodeConceptInfo(this.ownNode.getNativeObj(), conceptTag); //修改节点描述信息
			};
			
			this.modifyNodeSpatialRefInfo=function(spatialTag){
				Module.modifyNodeSpatialRefInfo(this.ownNode.getNativeObj(), spatialTag); //修改节点描述信息
			};
			
			this.modifyNodeUnitInfo=function(unitTag){
				Module.modifyNodeUnitInfo(this.ownNode.getNativeObj(), unitTag); //修改节点描述信息
			};
			
			this.modifyNodeDataTemplateInfo=function(dataTemplateTag){
				Module.modifyNodeDataTemplateInfo(this.ownNode.getNativeObj(), dataTemplateTag); //修改节点描述信息
			};
		}
		
		function UdxSchemaNode(pParentNode){
			this.parentNode = pParentNode;
			
			this.create=function(name, type, description){
				this.nativeObj=Module.addChildNode(this.parentNode.getNativeObj(), name, type, description);
				this.description=new UdxNodeDescription(this);
			};
			
			this.getNativeObj=function(){
				return this.nativeObj;
			};
			
			this.getDescription=function(){
				return this.description;
			};
			
			this.getNodeName=function(){
				var name = Module.getNodeName(this.nativeObj); //节点名称
				return name;
			};
			
			this.setNodeName=function(name){
				Module.modifyNodeName(this.nativeObj, name); //修改节点名称
			};
			
			this.getNodeType=function(){
				var nodeType = Module.getNodeType(this.nativeObj); //节点类型
				return nodeType;
			};
			
			this.addChildNode=function(name, type, description){
				var cNode = new UdxSchemaNode(this);
				cNode.create(name, type, description);
				if (cNode.getNativeObj==0) return undefined;
				return cNode;
			};
			
			this.getChildNodeCount=function(){
				return Module.getNodeChildCount(this.nativeObj);
			};
			
			this.getChildNode=function(idx){
				var node_native_obj = Module.getChildNode(this.nativeObj,idx);
				var node = new UdxSchemaNode(this);
				node.nativeObj = node_native_obj;
				node.description = new UdxNodeDescription(node);
				return node;
			}
		};
		
		function UdxSchemaDataset(){		
			this.createDataset=function(){
				this.dataset = Module.createUdxDatasetSchema(); //创建一个Dataset
				this.nativeObj = Module.getRootNode(this.dataset); //获取Dataset的根节点
				this.description = new UdxNodeDescription(this);
			};
			
			this.createDatasetWithPointer=function(datasetObj){
				this.dataset = datasetObj;
				this.nativeObj = Module.getRootNode(this.dataset);
				this.description = new UdxNodeDescription(this);
			};
			
			this.getDatasetObj=function(){
				return this.dataset;
			};
			
			this.formatToXmlStream=function(){
				var xml_str = Module.formatToXmlStream(this.dataset);
				console.log(xml_str);
			};
			
			this.loadFromXmlStream=function(xml_str){
				Module.loadFromXmlStream(this.dataset, xml_str);
			};
		};
		
		UdxSchemaDataset.prototype = new UdxSchemaNode();
		
	</script>
	
	<script type="text/javascript">
		var EExecutionStyle = { //模型执行风格的枚举类型
　　　　	StateSimulation: Module.ModelExecutionStyle.E_STATE_SIMULATION,     //!状态模拟
　　　　	SimpleCalculation: Module.ModelExecutionStyle.E_SIMPLE_CALCULATION,	//!简单计算
　　　　	TimeSeries: Module.ModelExecutionStyle.E_TIME_SERIES				//!时间推进
　　　　};

		var ELocalizationType ={ //模型本地化信息的枚举类型
			ZH_CN: Module.LocalizationType.E_ZH_CN,  		  //中文
			EN_US: Module.LocalizationType.E_EN_US,  		  //英文
			DE_DE: Module.LocalizationType.E_DE_DE,  		  //法文
			RU_RU: Module.LocalizationType.E_RU_RU,  		  //俄文
			AR: Module.LocalizationType.E_AR, 		 		  //阿拉伯文
			ES: Module.LocalizationType.E_ES, 		 		  //西班牙文
			COUNT: Module.LocalizationType.E_COUNT	 		  //数目
		};
		
		var EModelEventType = { //模型事件信息的枚举类型
			RESPONSE: Module.ModelEventType.E_RESPONSE,       //由外部响应数据（输入）
			NORESPONSE: Module.ModelEventType.E_NORESPONSE,   //由内部分发数据（输出）
			CONTROL: Module.ModelEventType.E_CONTROL		  //控制参数（输入或内置）
		};

		var EModelStateType={ //模型状态信息的枚举类型
			BASIC: Module.ModelStateType.E_BASIC, 			  //基本状态
			GROUP: Module.ModelStateType.E_GROUP  			  //组合状态
		};
		
		var EModelDatasetItemType={ //模型数据描述信息的枚举类型
			INTERNAL: Module.ModelDatasetItemType.E_INTERNAL, //内部定义数据
			EXTERNAL: Module.ModelDatasetItemType.E_EXTERNAL  //外部引用数据
		};
		
		////////////////////////////////////////////////////////////////////////
		//
		//
		//
		////////////////////////////////////////////////////////////////////////
		function ModelCategory(){ //模型分类信息
			this.categoryPrinciple = ""; 					  //分类原则（分类体系的ID）
			this.categoryPath = "";		 					  //分类路径（分类体系中的具体分类）
		};
		
		function ModelLocalization(){ //模型本地化信息
			this.localType = Module.LocalizationType.E_COUNT; //本地化信息的类型
			this.localName = "name";						  //本地化信息的名称
			this.abstractInfo = "abstract";					  //本地化信息的摘要
			this.wikiUrl = "wiki";							  //本地化信息的网络资源（路由到外部的元数据文档）
			this.keywords = [];		  //本地化信息的关键字
		};
		
		function ModelDatasetItem(){ //模型数据描述的条目信息
			this.datasetItem = null;								//条目关联的UDX Schema对象
			this.datasetName = "";									//数据描述条目名称（需要全局唯一，不可重复）
			this.datasetItemType = EModelDatasetItemType.INTERNAL;	//数据描述条目类型（内联/外引）
			this.datasetItemDescription = "";						//数据描述条目的说明信息
			this.externalId = "";									//数据描述条目的外引ID
		};
		
		function ModelEvent(){ //模型事件
			this.eventName="";								  //模型事件名称
			this.eventType=EModelEventType.CONTROL;			  //模型事件类型（输入/输出/控制）
			this.eventDescription = "";						  //模型事件的描述信息
			this.datasetReference = "";						  //模型事件关联的数据条目ID
			this.parameterDescription = "";					  //模型事件的参数描述信息
			this.optional = false;							  //模型事件是否为可选
		};
		
		function ModelState(){ //模型状态
			this.stateId = "";								  //模型状态ID（UID类型）
			this.stateName = "";							  //模型状态的名称
			this.StateType = EModelStateType.BASIC;			  //模型状态的类型（Basic/Group）
			this.stateDescription = ""; 					  //模型状态的描述信息
			this.modelEvents = [];							  //模型状态的事件信息
		};
		
		function ModelStateTransition(){ //模型状态迁移
			this.fromState = "";							  //模型状态迁移的起始State
			this.toState = "";								  //模型状态迁移的终止State
		};
		
		function HardwareRequirement(){ //模型的硬件需求信息
			this.requirementKey = "";
			this.requirementValue = "";
		};
		
		function SoftwareRequirement(){ //模型的软件需求信息
			this.requirementKey = "";
			this.requirementValue = "";
		};
		
		function ModelAssembly(){ //模型的运行需求信息
			this.assemblyName = "";
			this.assemblyPath = "";
		};
		
		function SupportiveResource(){ //模型的硬件需求信息
			this.resourceType = "";
			this.resourceName = "";
		};
		
		////////////////////////////////////////////////////////////////////////
		//
		//
		//
		////////////////////////////////////////////////////////////////////////
		function ModelAttributeClass(modelClass) { //模型属性对象
			this.modelClassObj = modelClass;
			this.modelAttributeObj = Module.getModelAttribute(this.modelClassObj);
		};
		
		function ModelBehaviorClass(modelClass){ //模型行为对象
			this.modelClassObj = modelClass;
			this.modelBehaviorObj = Module.getModelBehavior(this.modelClassObj);
		};
		
		function ModelRuntimeClass(modelClass){ //模型运行时对象
			this.modelClassObj = modelClass;
			this.modelRuntimeObj = Module.getModelRuntime(this.modelClassObj);
		};
		
		function ModelClass(){  //模型结构化描述的Class对象
			this.modelClassObj = Module.createModelClass();
			this.name = "";
			this.uid = "";
			this.executionStyle = EExecutionStyle.StateSimulation;
			this.modelAttribute = new ModelAttributeClass(this.modelClassObj);
			this.modelBehavior = new ModelBehaviorClass(this.modelClassObj);
			this.modelRuntime = new ModelRuntimeClass(this.modelClassObj);
			
			this.getModelAttribute=function(){return this.modelAttribute;}
			this.getModelBehavior=function(){return this.modelBehavior;}
			this.getModelRuntime=function(){return this.modelRuntime;}
			
			this.setModelName=function(name){Module.setModelName(this.modelClassObj, name);}
			this.getModelName=function(){return Module.getModelName(this.modelClassObj);}
			this.setModelUID=function(uid){Module.setModelUID(this.modelClassObj, uid);}
			this.setModelExecutionStyle=function(style){Module.setModelExecutionStyle(this.modelClassObj, style);}
			
			this.formatToXmlStream=function(){
				var model_xml = Module.FormatToXmlStream(this.modelClassObj);
				console.log(model_xml);
				return model_xml;
			}
			
			this.loadFromXmlStream=function(pXmlStr){
				var ret = Module.LoadFromXmlStream(this.modelClassObj, pXmlStr);
				console.log("load result: "+ret);
			}
			
			this.compareWithOther=function(pModelClass, withRuntime){
				var ret = Module.CompareModelClassObject(this.modelClassObj, pModelClass.modelClassObj,withRuntime);
				return ret;
			}
		};
		
		////////////////////////////////////////////////////////////////////////
		//
		//
		//
		////////////////////////////////////////////////////////////////////////
		ModelAttributeClass.prototype = {
			addCategoryInfo: function(ModelCategory){
				Module.addCategoryInfo(this.modelAttributeObj,
					ModelCategory.categoryPrinciple,
					ModelCategory.categoryPath);
			},
			
			getCategoryCount: function(){
				return Module.getCategoryCount(this.modelAttributeObj);
			},
			
			getCategory: function(idx){
				var category;
				category.categoryPrinciple = Module.getCategory_Principle(this.modelAttributeObj, idx);
				category.categoryPath = Module.getCategory_Path(this.modelAttributeObj, idx);
			},
			
			removeCategory: function(idx){
				return Module.removeCategory(this.modelAttributeObj, idx);
			},
	
			updateCategory: function(idx, pModelCategory){
				return Module.updateCategory(this.modelAttributeObj, idx,
					pModelCategory.categoryPrinciple,
					pModelCategory.categoryPath);
			},
			
			///////////////////////////////////////////////////////////////////////////
			addLocalAttributeInfo: function(pModelLocalization){
				Module.addLocalAttributeInfo(this.modelAttributeObj,
					pModelLocalization.localType,
					pModelLocalization.localName,
					pModelLocalization.abstractInfo,
					pModelLocalization.wikiUrl);
				for(var i=0; i<pModelLocalization.keywords.length; i++)
				{
					Module.addLocalAttributeInfo_Keyword(this.modelAttributeObj,
						pModelLocalization.localType,
						pModelLocalization.keywords[i]);
				}
			},
			
			getLocalAttributeCount: function(){
				return Module.getLocalAttributeCount(this.modelAttributeObj);
			},
			
			getLocalAttributeByIndex: function(idx){
				var localInfo;
				localInfo.type = Module.getLocalAttributeByIndex_LocalType(this.modelAttributeObj, idx);
				localInfo.name = Module.getLocalAttributeByIndex_LocalName(this.modelAttributeObj, idx);
				localInfo.abstractInfo = Module.getLocalAttributeByIndex_AbstractInfo(this.modelAttributeObj, idx);
				localInfo.wiki = Module.getLocalAttributeByIndex_WikiUrl(this.modelAttributeObj, idx);
				
				var keyword_count = Module.getLocalAttributeByIndex_KeywordCount(this.modelAttributeObj, idx);
				for(var i=0; i<keyword_count; i++)
				{
					var temp_keyw = Module.getLocalAttributeByIndex_KeywordWithIndex(this.modelAttributeObj, idx, i);
					localInfo.keywords.add(temp_keyw);
				}
			},
			
			removeLocalAttributeByIndex: function(idx){
				return Module.removeLocalAttributeByIndex(this.modelAttributeObj, idx);
			}
		};
		
		ModelBehaviorClass.prototype = {
			addModelDatasetItem:function(pDataset){
				Module.addModelDatasetItem(this.modelBehaviorObj,
					pDataset.datasetItem.getDatasetObj(), pDataset.datasetName, pDataset.datasetItemType,
					pDataset.datasetItemDescription, pDataset.externalId);
			},

			removeModelDatasetItem:function(pDataset){
				Module.removeModelDatasetItem(this.modelBehaviorObj,pDataset.datasetName);
			},

			getModelDatasetItemCount:function(){
				return Module.getModelDatasetItemCount(this.modelBehaviorObj);
			},

			getModelDatasetItem:function(idx){
				var pDataset = new ModelDatasetItem();
				var datasetObj = Module.getModelDatasetItem_Dataset(this.modelBehaviorObj, idx);
				pDataset.datasetItem = new UdxSchemaDataset();
				pDataset.datasetItem.createDatasetWithPointer(datasetObj);
				pDataset.datasetName = Module.getModelDatasetItem_Name(this.modelBehaviorObj, idx);
				pDataset.datasetItemType = Module.getModelDatasetItem_Type(this.modelBehaviorObj, idx);
				pDataset.datasetItemDescription = Module.getModelDatasetItem_Description(this.modelBehaviorObj, idx);
				pDataset.externalId = Module.getModelDatasetItem_ExternalId(this.modelBehaviorObj, idx);
				return pDataset;
			},
			
			///////////////////////////////////////////////////////////////////////////
			addModelState:function(pState){
				Module.addModelState(this.modelBehaviorObj,
					pState.stateId, pState.stateName, pState.stateType, pState.stateDescription);
				for(var i=0; i<pState.modelEvents.length; i++)
				{
					Module.addModelState_Event(this.modelBehaviorObj, pState.stateId,
						pState.modelEvents[i].eventName, pState.modelEvents[i].eventType,
						pState.modelEvents[i].eventDescription, pState.modelEvents[i].datasetReference,
						pState.modelEvents[i].parameterDescription, pState.modelEvents[i].optional);
				}
			},
			
			removeModelState:function(pState){
				Module.removeModelState(this.modelBehaviorObj, pState.stateId);
			},
			
			updateModelState:function(pState){
				this.removeModelState(pState);
				this.addModelState(pState);
			},
			
			getModelStateCount:function(){
				return Module.getModelStateCount(this.modelBehaviorObj);
			},
			
			getModelState:function(idx){
				var pState = new ModelState();
				pState.stateId = Module.getModelState_Id(this.modelBehaviorObj,idx);
				pState.stateName = Module.getModelState_Name(this.modelBehaviorObj,idx);
				pState.stateType = Module.getModelState_Type(this.modelBehaviorObj,idx);
				pState.stateDescription = Module.getModelState_Decription(this.modelBehaviorObj,idx);
				var event_count = Module.getModelState_EventCount(this.modelBehaviorObj, idx);
				for(var iEvent=0; iEvent<event_count; iEvent++)
				{
					var temp_event = new ModelEvent();
					temp_event.eventName = Module.getModelState_Event_Name(this.modelBehaviorObj, idx, iEvent);
					temp_event.eventType = Module.getModelState_Event_Type(this.modelBehaviorObj, idx, iEvent);
					temp_event.eventDescription = Module.getModelState_Event_Description(this.modelBehaviorObj, idx, iEvent);
					temp_event.datasetReference = Module.getModelState_Event_DatasetReference(this.modelBehaviorObj, idx, iEvent);
					temp_event.parameterDescription = Module.getModelState_Event_ParameterDescription(this.modelBehaviorObj, idx, iEvent);
					temp_event.optional = Module.getModelState_Event_Optional(this.modelBehaviorObj, idx, iEvent);
					pState.modelEvents.add(temp_event);
				}
				return pState;
			},
			
			/////////////////////////////////////////////////////////////////////////////
			getModelState_EventCount:function(stateIdx){
				return Module.getModelState_EventCount(this.modelBehaviorObj, stateIdx);
			},
			
			getModelState_Event:function(){
				var temp_event = new ModelEvent();
				temp_event.eventName = Module.getModelState_Event_Name(this.modelBehaviorObj, idx, iEvent);
				temp_event.eventType = Module.getModelState_Event_Type(this.modelBehaviorObj, idx, iEvent);
				temp_event.eventDescription = Module.getModelState_Event_Description(this.modelBehaviorObj, idx, iEvent);
				temp_event.datasetReference = Module.getModelState_Event_DatasetReference(this.modelBehaviorObj, idx, iEvent);
				temp_event.parameterDescription = Module.getModelState_Event_ParameterDescription(this.modelBehaviorObj, idx, iEvent);
				temp_event.optional = Module.getModelState_Event_Optional(this.modelBehaviorObj, idx, iEvent);
				return temp_event;
			},
			
			/////////////////////////////////////////////////////////////////////////////
			addModelStateTransition:function(fromId, toId){
				Module.addModelStateTransition(this.modelBehaviorObj, fromId, toId);
			},
			
			removeModelStateTransition:function(fromId, toId){
				Module.removeModelStateTransition(this.modelBehaviorObj, fromId, toId);
			},
			
			getModelStateTransitionCount:function(){
				return Module.getModelStateTransitionCount(this.modelBehaviorObj);
			},
			
			getModelStateTransition:function(){
				var transition = new ModelStateTransition();
				transition.fromState = Module.getModelStateTransition_From(this.modelBehaviorObj);
				transition.toState = Module.getModelStateTransition_To(this.modelBehaviorObj);
			},
			
			existModelStatetTransition:function(fromId, toId){
				return Module.existModelStatetTransition(this.modelBehaviorObj,fromId, toId);
			},
			
			updateModelStateTransition:function(idx, fromId, toId){
				return Module.updateModelStateTransition(this.modelBehaviorObj,idx,fromId,toId);
			}
		};
	
		ModelRuntimeClass.prototype = {
			getAliasName:function(){
				Module.getAliasName(this.modelRuntimeObj);
			},
			setAliasName:function(name){
				Module.setAliasName(this.modelRuntimeObj,name);
			},
			
			getRuntimeVersion:function(){
				Module.getRuntimeVersion(this.modelRuntimeObj);
			},
			setRuntimeVersion:function(version){
				Module.setRuntimeVersion(this.modelRuntimeObj,version);
			},
			
			getEntry:function(){
				Module.getEntry(this.modelRuntimeObj);
			},
			setEntry:function(entry){
				Module.setEntry(this.modelRuntimeObj,entry);
			},
			
			getBaseDirectory:function(){
				Module.getBaseDirectory(this.modelRuntimeObj);
			},
			setBaseDirectory:function(baseDir){
				Module.setBaseDirectory(this.modelRuntimeObj,baseDir);
			},
			/////////////////////////////////////////////////////////
			addHardwareRequirement:function(hardwareInfo){
				Module.addHardwareRequirement(this.modelRuntimeObj, 
					hardwareInfo.requirementKey, hardwareInfo.requirementValue);
			},
			
			addSoftwareRequirement:function(softwareInfo){
				Module.addSoftwareRequirement(this.modelRuntimeObj, 
					softwareInfo.requirementKey, softwareInfo.requirementValue);
			},
			
			addModelAssembly:function(assemblyInfo){
				Module.addModelAssembly(this.modelRuntimeObj, 
					assemblyInfo.assemblyName, assemblyInfo.assemblyPath);
			},
			
			addSupportiveResource:function(supportInfo){
				Module.addSupportiveResource(this.modelRuntimeObj, 
					supportInfo.resourceType, supportInfo.resourceName);
			},
			/////////////////////////////////////////////////////////
			getHardwareRequirementCount:function(){
				return Module.getHardwareRequirementCount(this.modelRuntimeObj);
			},
			getSoftwareRequirementCount:function(){
				return Module.getSoftwareRequirementCount(this.modelRuntimeObj);
			},
			getModelAssemblyCount:function(){
				return Module.getModelAssemblyCount(this.modelRuntimeObj);
			},
			getSupportiveResourceCount:function(){
				return Module.getSupportiveResourceCount(this.modelRuntimeObj);
			},
			/////////////////////////////////////////////////////////
			getHardwareRequirement:function(idx){
				var requirement = new HardwareRequirement();
				requirement.requirementKey=Module.getHardwareRequirement_RequirementKey(this.modelRuntimeObj,idx);
				requirement.requirementValue=Module.getHardwareRequirement_RequirementValue(this.modelRuntimeObj,idx);
				return requirement;
			},
			getSoftwareRequirement:function(idx){
				var requirement = new SoftwareRequirement();
				requirement.requirementKey=Module.getSoftwareRequirement_RequirementKey(this.modelRuntimeObj,idx);
				requirement.requirementValue=Module.getSoftwareRequirement_RequirementValue(this.modelRuntimeObj,idx);
				return requirement;
			},
			getModelAssembly:function(idx){
				var requirement = new ModelAssembly();
				requirement.assemblyName=Module.getModelAssembly_AssemblyName(this.modelRuntimeObj,idx);
				requirement.assemblyPath=Module.getModelAssembly_AssemblyPath(this.modelRuntimeObj,idx);
				return requirement;
			},
			getSupportiveResource:function(idx){
				var requirement = new SupportiveResource();
				requirement.resourceType=Module.getSupportiveResource_ResourceType(this.modelRuntimeObj,idx);
				requirement.resourceName=Module.getSupportiveResource_ResourceName(this.modelRuntimeObj,idx);
				return requirement;
			},
			//////////////////////////////////////////////////////////
			removeHardwareRequirement:function(idx){
				Module.removeHardwareRequirement(this.modelRuntimeObj,idx);
			},
			removeSoftwareRequirement:function(idx){
				Module.removeSoftwareRequirement(this.modelRuntimeObj,idx);
			},
			removeModelAssembly:function(idx){
				Module.removeModelAssembly(this.modelRuntimeObj,idx);
			},
			removeSupportiveResource:function(idx){
				Module.removeSupportiveResource(this.modelRuntimeObj,idx);
			}
		}
	</script>
	
    <script type='text/javascript'>
	  function sasa(){
		var modelClass = new ModelClass();
		modelClass.setModelName("模型名称陈旻Name");
		modelClass.setModelUID("{472F0F71-4DD6-4BE9-86CC-0C6B9BD809D1}");
		modelClass.setModelExecutionStyle(EExecutionStyle.SimpleCalculation);
		
		///////////////////////////////////////////////////////////
		//
		// 模型属性AttributeSet
		//
		///////////////////////////////////////////////////////////
		var modelAttribute = modelClass.getModelAttribute();
		
		var modelCate1 = new ModelCategory();
		{
			modelCate1.categoryPrinciple = "principle1";
			modelCate1.categoryPath = "path1";
		}
		modelAttribute.addCategoryInfo(modelCate1);
		
		var modelLocalInfo1 = new ModelLocalization();
		{
			modelLocalInfo1.localType = ELocalizationType.EN_US;
			modelLocalInfo1.localName = "name";
			modelLocalInfo1.abstractInfo = "abstract, this is about some abstract information";
			modelLocalInfo1.wikiUrl = "http://en.njnu.edu.cn";
			modelLocalInfo1.keywords.push("keyword1");
			modelLocalInfo1.keywords.push("keyword2");
			modelLocalInfo1.keywords.push("keyword3");
		}
		modelAttribute.addLocalAttributeInfo(modelLocalInfo1);
				
		/*var modelLocalInfo2 = new ModelLocalization();
		{
			modelLocalInfo2.localType = ELocalizationType.ZH_CN;
			modelLocalInfo2.localName = "名称";
			modelLocalInfo2.abstractInfo = "摘要, 这是一段摘要信息";
			modelLocalInfo2.wikiUrl = "http://www.njnu.edu.cn";
			modelLocalInfo2.keywords.push("关键字1");
			modelLocalInfo2.keywords.push("关键字2");	
		}
		modelAttribute.addLocalAttributeInfo(modelLocalInfo2);*/

		
		///////////////////////////////////////////////////////////
		//
		// 模型行为Behavior
		//
		///////////////////////////////////////////////////////////
		var modelBehavior = modelClass.getModelBehavior();
		var temp_dataItem = new ModelDatasetItem();
		{
			var dataset = new UdxSchemaDataset();
			dataset.createDataset();
			dataset.setNodeName("hah");
			dataset.getDescription().modifyNodeDescription("new desc");
			var node1 = dataset.addChildNode("name1", ESchemaNodeType.EDTKT_NODE, "description1");
			var node1_1 = node1.addChildNode("name1_1", ESchemaNodeType.EDTKT_INT, "description1_1");
			var node1_2 = node1.addChildNode("name1_2", ESchemaNodeType.EDTKT_REAL, "description1_2");
			temp_dataItem.datasetItem = dataset;
			temp_dataItem.datasetName = "data item1";
			temp_dataItem.datasetItemType = EModelDatasetItemType.INTERNAL;
			temp_dataItem.datasetItemDescription = "data item1 description";
		}
		modelBehavior.addModelDatasetItem(temp_dataItem);
		
		var temp_dataItem1 = new ModelDatasetItem();
		{
			var dataset = new UdxSchemaDataset();
			dataset.createDataset();
			var node1 = dataset.addChildNode("name1", ESchemaNodeType.EDTKT_INT, "description1_1");
			var node2 = dataset.addChildNode("name2", ESchemaNodeType.EDTKT_REAL, "description1_2");
			var node3 = dataset.addChildNode("name3", ESchemaNodeType.EDTKT_STRING, "description1_3");
			var node4 = dataset.addChildNode("name4", ESchemaNodeType.EDTKT_VECTOR2, "description1_4");
			temp_dataItem1.datasetItem = dataset;
			temp_dataItem1.datasetName = "data item2";
			temp_dataItem1.datasetItemType = EModelDatasetItemType.INTERNAL;
			temp_dataItem1.datasetItemDescription = "data item2 description";
		}
		modelBehavior.addModelDatasetItem(temp_dataItem1);
		
		var temp_dataItem2 = modelBehavior.getModelDatasetItem(0);
		temp_dataItem2.datasetItem.formatToXmlStream();
		/////////////////////////////以上是数据引用//////////////////////////////////
		
		/////////////////////////////以下是模型状态和事件////////////////////////////
		var temp_state1 = new ModelState();
		{
			temp_state1.stateId = "{EC9FD8A7-CD8B-4715-9489-907AD1B34E9D}";
			temp_state1.stateName = "State_1";
			temp_state1.stateType = EModelStateType.BASIC;
			temp_state1.stateDescription = "状态描述信息";
			var temp_event1 = new ModelEvent();
			{
				temp_event1.eventName="事件Event";
				temp_event1.eventType=EModelEventType.RESPONSE;
				temp_event1.eventDescription = "事件描述";
				temp_event1.datasetReference = temp_dataItem2.datasetName;
				temp_event1.parameterDescription = "参数描述";
				temp_event1.optional = false;
			}
			temp_state1.modelEvents.push(temp_event1);
		}
		modelBehavior.addModelState(temp_state1);
		
		var temp_state2 = new ModelState();
		{
			temp_state2.stateId = "{F1D3B6D9-BCB1-4439-9A4A-57876B25D66D}";
			temp_state2.stateName = "State_1";
			temp_state2.stateType = EModelStateType.BASIC;
			temp_state2.stateDescription = "状态描述信息";
			var temp_event1 = new ModelEvent();
			{
				temp_event1.eventName="事件Event";
				temp_event1.eventType=EModelEventType.RESPONSE;
				temp_event1.eventDescription = "事件描述";
				temp_event1.datasetReference = temp_dataItem1.datasetName;
				temp_event1.parameterDescription = "参数描述";
				temp_event1.optional = false;
			}
			temp_state2.modelEvents.push(temp_event1);
		}
		modelBehavior.addModelState(temp_state2);
		
		{ //更新某个状态
			var temp_event2 = new ModelEvent();
			temp_event2.eventName="事件Event2";
			temp_event2.eventType=EModelEventType.NORESPONSE;
			temp_event2.eventDescription = "事件描述1";
			temp_event2.datasetReference = temp_dataItem.datasetName;
			temp_event2.parameterDescription = "参数描述2";
			temp_event2.optional = true;
			temp_state2.modelEvents.push(temp_event2);	
		}
		modelBehavior.updateModelState(temp_state2);
		
		//添加状态之间的转换
		modelBehavior.addModelStateTransition(temp_state1.stateId, temp_state2.stateId);
		
		///////////////////////////////////////////////////////////
		//
		// 模型运行时Runtime
		//
		///////////////////////////////////////////////////////////
		var modelRuntime = modelClass.getModelRuntime();
		modelRuntime.setAliasName("model alias name");
		modelRuntime.setRuntimeVersion("5.4");
		modelRuntime.setBaseDirectory("$installpath/taudem/");
		modelRuntime.setEntry("ppp.config");
		
		var hardwareInfo = new HardwareRequirement();
		hardwareInfo.requirementKey = "主频"
		hardwareInfo.requirementValue = "2.4";
		modelRuntime.addHardwareRequirement(hardwareInfo);
		
		var softwareInfo = new SoftwareRequirement();
		softwareInfo.requirementKey = "内存"
		softwareInfo.requirementValue = "120M";
		modelRuntime.addSoftwareRequirement(softwareInfo);
		
		var assemblyInfo = new ModelAssembly();
		assemblyInfo.assemblyName = "dll";
		assemblyInfo.assemblyPath = "./mpi.dll";
		modelRuntime.addModelAssembly(assemblyInfo);
		
		var supportInfo = new SupportiveResource();
		supportInfo.resourceType = "data";
		supportInfo.resourceName = "dsf.csv";
		modelRuntime.addSupportiveResource(supportInfo);
		
		var xml_str = modelClass.formatToXmlStream();
		
		///////////////////////////////////////////////////////////
		//
		// 以下是对两个ModelClass进行对比
		//
		///////////////////////////////////////////////////////////
		var modelClass1 = new ModelClass();
		modelClass1.loadFromXmlStream(xml_str);
		
		if (false)
		{
			var modelBehavior1 = modelClass1.getModelBehavior();
			var temp_state3 = new ModelState();
			{
				temp_state3.stateId = "{365D52B9-4651-4D6C-89E4-F08A39DE6424}";
				temp_state3.stateName = "State_3";
				temp_state3.stateType = EModelStateType.BASIC;
				temp_state3.stateDescription = "状态描述信息";
				var temp_event1 = new ModelEvent();
				{
					temp_event1.eventName="事件Event";
					temp_event1.eventType=EModelEventType.RESPONSE;
					temp_event1.eventDescription = "事件描述";
					temp_event1.datasetReference = temp_dataItem2.datasetName;
					temp_event1.parameterDescription = "参数描述";
					temp_event1.optional = false;
				}
				temp_state3.modelEvents.push(temp_event1);
			}
			modelBehavior1.addModelState(temp_state3);
		}
		if (true)
		{
			var modelRuntime1 = modelClass1.getModelRuntime();
			var softwareInfo1 = new SoftwareRequirement();
			softwareInfo1.requirementKey = "OperationSystem"
			softwareInfo1.requirementValue = "Windows";
			modelRuntime1.addSoftwareRequirement(softwareInfo1);
		}
		modelClass1.formatToXmlStream();
		
		var compareRet = modelClass.compareWithOther(modelClass1,true);
		console.log("compare result:"+compareRet);
	  }
    </script>
  </body>
</html>
